#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Name:     launcher.py
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Version:  111201

#qstyle = '''
#/*QtGui.QWidget{ background-image: url(res/tex.png) }*/
#QAbstractScrollArea, QtGui.QPushButton { background-image: None}
#
#/*背景色*/
#QtGui.QWidget{ background-color: bgdColor }
#QtGui.QPushButton,QtGui.QSplashScreen{background-color: None}
#
#/*menu*/
#QtGui.QMenuBar {
#background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
#stop:0 lightgray, stop:1 darkgray);
#}
#QtGui.QMenu {
#margin: 2px; /* some spacing around the menu */
#}
#QtGui.QMenu::item:selected {
#border-color: borderColor;
#background: rgba(100, 100, 100, 150);
#}
#
#/*按钮*/
#QtGui.QPushButton{
#border: 3px outset borderColor;
#background-color: bgdColor;
#padding: 5px;
#border-radius: 5px;
#}
#QtGui.QPushButton:checked {border-color: red}
#/*醒目按下的按钮*/
#QtGui.QPushButton:pressed {border-color: green}
#
#/*QSlider*/
#QSlider::groove { background: gray; }
#QSlider::groove:horizontal { height: 6px;}
#QSlider::groove:vertical { width: 6px;}
#QSlider::handle {
#border: 1px solid borderColor;
#border-radius: 3px;
#background: bgdColor;
#}
#QSlider::handle:horizontal { width: 18px; margin: -3px 0 ; }
#QSlider::handle:vertical { height: 18px; margin: 0 -3px ; }
#QSlider::add-page { background: gray; }
#QSlider::sub-page { background: green;}
#
#/*QtGui.QTableView*/
#QtGui.QTableView {
#alternate-background-color: darkContentColor;
#background-color: contentColor;
#}
#'''
#
#COLOR_MAP = {
#        'borderColor':'gray',
#        'bgdColor':'#FCF6E4',
#        'contentColor':'#E1EDFB',
#        'darkContentColor':'#CDE2F8'
#        }
#
#for k, v in COLOR_MAP.items():
#    qstyle = qstyle.replace(k, v)
#

def launch():
    from PySide import QtGui, QtCore
    import sys, os

    #qstyle = QtGui.QStyleFactory.create('Plastique')

    app = QtGui.QApplication(sys.argv)
    #app.setStyleSheet(qstyle)
    #app.setStyle(qstyle)

    splash = QtGui.QSplashScreen(QtGui.QPixmap('share/splash/splashscreen.png'))
    splash.show()

    from window import Window
    import resource_rc
    from utils import Settings, SETTINGS_FILE
    from plugins import Transdirs

    #import time
    #time.sleep(40)

    settings = Settings(SETTINGS_FILE).get_settings()

    trans_list = []

    for dir in ['share/trans'] + Transdirs:
        try:
            trans_list.append(QtCore.QTranslator())
            trans_list[-1].load('%s%s%s.qm' %(dir, os.sep, settings.lang))
            app.installTranslator(trans_list[-1])
        except Exception, e:
            sys.stderr.write('Error: %s\n' %e)
    win = Window()
    win.show()

    splash.finish(win)

    sys.exit(app.exec_())

if __name__=='__main__':
    launch()
